using System;
using System.ComponentModel;
using System.Transactions;

using SIS.ENT;
using SIS.DAL;


namespace SIS.BLL
{

    /// <summary>
    /// The StudentAddressTableManager class is responsible for managing BO.StudentAddressTable objects in the system.
    /// </summary>
    [DataObjectAttribute()]
    public class StudentAddressTableManager
    {

        #region "Public Methods"

        /// <summary>
        /// Gets a list with all StudentAddressTable objects in the database.
        /// </summary>
        /// <returns>A list with all StudentAddressTable from the database when the database contains any, or null otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public static StudentAddressTableList GetList()
        {
            return StudentAddressTableDB.GetList();
        }

        /// <summary>
        /// Gets a single StudentAddressTable from the database without its data.
        /// </summary>
        /// <param name="studentAddressKey">The StudentAddressKey of the StudentAddressTable in the database.</param>
        /// <returns>A StudentAddressTable object when the StudentAddressKey exists in the database, or <see langword="null"/> otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static StudentAddressTable GetItem(int studentAddressKey)
        {
            return GetItem(studentAddressKey, false);
        }

        /// <summary>
        /// Gets a single StudentAddressTable from the database.
        /// </summary>
        /// <param name="studentAddressKey">The StudentAddressKey of the StudentAddressTable in the database.</param>
        /// <param name="getStudentAddressTableRecords">Determines whether to load all associated StudentAddressTable records as well.</param>
        /// <returns>
        /// A StudentAddressTable object when the StudentAddressKey exists in the database, or <see langword="null"/> otherwise.
        /// </returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static StudentAddressTable GetItem(int studentAddressKey, bool getStudentAddressTableRecords)
        {
            StudentAddressTable myStudentAddressTable = StudentAddressTableDB.GetItem(studentAddressKey);
            return myStudentAddressTable;
        }

        /// <summary>
        /// Gets a single StudentAddressTable from the database.
        /// </summary>
        /// <param name="UserAccountKey">The UserAccountKey of the StudentAddressTable in the database.</param>
        /// <returns>
        /// A StudentAddressTable object when the StudentAddressKey exists in the database, or <see langword="null"/> otherwise.
        /// </returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static StudentAddressTable GetItemByUserAccountKey(int UserAccountKey, Int16 AddressTypeCode)
        {
            StudentAddressTable myStudentAddressTable = StudentAddressTableDB.GetItemByUserAccountKey(UserAccountKey, AddressTypeCode);
            return myStudentAddressTable;
        }

        /// <summary>
        /// Gets a single StudentAddressTable from the database.
        /// </summary>
        /// <param name="UserAccountKey">The UserAccountKey of the StudentAddressTable in the database.</param>
        /// <returns>
        /// A StudentAddressTable object when the StudentAddressKey exists in the database, or <see langword="null"/> otherwise.
        /// </returns>
        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public static StudentAddressTable GetItemByUserAccountKey(int UserAccountKey)
        {
            StudentAddressTable myStudentAddressTable = StudentAddressTableDB.GetItemByUserAccountKey(UserAccountKey);
            return myStudentAddressTable;
        }

        /// <summary>
        /// Saves a StudentAddressTable in the database.
        /// </summary>
        /// <param name="myStudentAddressTable">The StudentAddressTable instance to save.</param>
        /// <returns>The new StudentAddressKey if the StudentAddressTable is new in the database or the existing StudentAddressKey when an item was updated.</returns>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
        public static int Save(StudentAddressTable myStudentAddressTable)
        {
            using (TransactionScope myTransactionScope = new TransactionScope())
            {
                int studentAddressTableStudentAddressKey = StudentAddressTableDB.Save(myStudentAddressTable);

                //  Assign the StudentAddressTable its new (or existing StudentAddressKey).
                myStudentAddressTable.StudentAddressKey = studentAddressTableStudentAddressKey;

                myTransactionScope.Complete();

                return studentAddressTableStudentAddressKey;
            }
        }

        /// <summary>
        /// Deletes a StudentAddressTable from the database.
        /// </summary>
        /// <param name="myStudentAddressTable">The StudentAddressTable instance to delete.</param>
        /// <returns>Returns true when the object was deleted successfully, or false otherwise.</returns>
        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public static bool Delete(StudentAddressTable myStudentAddressTable)
        {
            return StudentAddressTableDB.Delete(myStudentAddressTable.StudentAddressKey);
        }

        #endregion

    }

}
